package com.xujichang.base.extensions

import android.content.Context
import androidx.fragment.app.Fragment
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment

/*提示信息*/
fun Fragment.postToast(message: String) {
    requireContext().applicationContext.postToast(message)
}

/*查找导航点*/
fun Fragment.findNavController(label: String): NavController {
    var findFragment: Fragment? = this
    while (null != findFragment) {
        if (findFragment is NavHostFragment) {
            val controller = findFragment.navController
            if (label == controller.graph.label) {
                return controller
            }
        }
        findFragment = findFragment.parentFragment
    }
    throw RuntimeException("Not found NavController with the label :$label")
}